﻿//------------------------------------------------------------------------------
// System Name:    Customer Service Platform
// Component:      CIS Domestic CategoryManagement
// Created By:     Samara Jiang (samaraj@wicresoft.com)
// Created Date:   2011-1-27
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASB.CC.Business.CIS;
using ASBCC.Business;
using ASBCC.Business.CIS;
using ASBCC.Database.EntityFramework;

namespace BEGDC.CC.Web.CIS2.Admin
{
    /// <summary>
    ///  CIS Domestic CategoryManagement
    /// </summary>
    public partial class CategoryManagement : EntityPage
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override EntityDataSource EntitySource
        {
            get { return this.edsCategory; }
        }

        protected override TextBox EntitySearchTxt
        {
            get { return this.SearchText; }
        }

        protected override Button EntityAddBtn
        {
            get { return this.BtnAdd; }
        }

        protected override Button EntitySearchBtn
        {
            get { return this.Searchbtn; }
        }

        protected override Button EntityClearBtn
        {
            get { return this.Cleanbtn; }
        }

        protected override GridView EntityGrid
        {
            get { return this.gvCategory; }
        }

        protected override DetailsView EntityDetails
        {
            get { return this.dvCategory; }
        }

        protected override void OnEntityDisabling(int entityKey)
        {
            CategoryManagementHelper.SetCategoryDisabled(entityKey);

            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CID, "Category disabled. id=" + entityKey + "; name=" + CategoryManagementHelper.getName(entityKey));
        }

        protected override string GetEntityWhereExpression(string keyword)
        {
            return "(it.Name like N'%" + keyword + "%'"
                 + " or it.Description like N'%" + keyword + "%')";

        }

        protected override void OnEntityInserting(EntityDataSourceChangingEventArgs e)
        {
            var dc = e.Context;
            var category = e.Entity as Category;
            e.Cancel = true;
            CategoryManagementHelper.OnCategoryInserting(category.Name, category.Description);

        }

        protected override void OnEntityUpdating(EntityDataSourceChangingEventArgs e)
        {

        }


        protected void edsCategory_Inserted(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var category = e.Entity as Category;
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CID, "Category inserted. id=" + category.CateID + "; name=" + category.Name + "; Comment=" + category.Description);

        }

        protected void edsCategory_Updated(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var category = e.Entity as Category;
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CID, "Category updated. id=" + category.CateID + "; name=" + category.Name + "; Comment=" + category.Description);

        }
    }
}
